<!DOCTYPE html>
<!--
  ~ 版权所有:杭州火图科技有限公司
  ~ 地址:浙江省杭州市滨江区西兴街道阡陌路智慧E谷B幢4楼在地图中查看
  ~
  ~ (c) Copyright Hangzhou Hot Technology Co., Ltd.
  ~ Floor 4,Block B,Wisdom E Valley,Qianmo Road,Binjiang District
  ~ 2013-2016. All rights reserved.
  -->

<html xmlns:th="http://www.thymeleaf.org" lang="zh-CN">

<!--/*@thymesVar id="freightTemplates" type="java.util.List<com.shengtang.stagent.data.entity.freight.FreightTemplate>"*/-->

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>运费模板</title>
    <link rel="stylesheet" href="http://resali.huobanplus.com/cdn/normalize/4.2.0/normalize.css"/>
    <link rel="stylesheet" href="../../resource/css/freight.css" th:href="@{/resource/css/freight.css}"/>
    <link href="../../resource/css/plugins/sweetalert/sweetalert.css?v=4.0.0" rel="stylesheet" th:href="@{/resource/css/plugins/sweetalert/sweetalert.css?v=4.0.0}"/>
</head>
<body style="background-color: #fff;">
<div id="content">
    <h4>运费模板</h4>

    <div class="button">
        <button th:onclick="|javascript:window.location.href='@{/freight/templateDetail(proType=${proType})}'|" class="btn" type="button">新建运费模板</button>
    </div>
    <div class="freight-list">
        <table class="table" style="width: 100%;" th:each="freightTemplate:${freightTemplates}" th:id="'template_'+${freightTemplate.id}">
            <thead>
            <tr>
                <th colspan="7" class="table-th">
                    <div class="clearfix">
                        <h5 style="font-size: 15px;margin-left: -30px;" class="left" th:text="${freightTemplate.name}"></h5>
                        <h5 class="left" th:if="${freightTemplate.isShippingFree==1}">包邮</h5>
                        <ul class="horizonal right">
                            <!--<li th:if="${!freightTemplate.isDefault()}">-->
                            <!--<a th:href="|javascript:templateListHandler.setDefault(${freightTemplate.id});|"-->
                            <!--href="javascript:templateListHandler.setDefault(0);">设为默认</a></li>-->
                            <li><a href="javascript:;" th:href="@{/freight/templateDetail(id=${freightTemplate.id},proType=${proType})}">修改</a></li>
                            <li><a th:href="|javascript:templateListHandler.deleteTemplate(${freightTemplate.id});|"
                                   href="javascript:templateListHandler.deleteTemplate(0);">删除</a></li>
                        </ul>
                    </div>
                </th>
            </tr>
            </thead>
            <tbody>
            <tr>
                <td width="150px">运送方式</td>
                <td>运送至</td>
                <td width="150px" th:text="${freightTemplate.valuationWay==0}?'首件（件）':'首重（g）'">
                </td>
                <td width="100px">运费（元）</td>
                <td width="100px" th:text="${freightTemplate.valuationWay==0}?'续件（件）':'续重（g）'">续件（件）</td>
                <td width="100px">运费（元）</td>
                <td width="150x">免邮条件</td>
            </tr>
            <tr th:each="detail:${freightTemplate.freightTemplateDetails}" th:if="${freightTemplate.isShippingFree==0}">
                <td th:text="${detail.deliveryType.desc}">快递公司</td>
                <td th:text="${detail.isDefault==1}?'中国':${detail.areaDesc}">中国</td>
                <td th:text="${detail.firstItem}">1</td>
                <td th:text="${detail.firstFreight}">2</td>
                <td th:text="${detail.nextItem}">1</td>
                <td th:text="${detail.nextFreight}">2</td>
                <td>
                    <th:block th:if="${detail.freeFreightItem>0}">
                        满<span th:text="${detail.freeFreightItem}"></span>件免邮
                    </th:block>
                </td>
            </tr>
            <tr th:if="${freightTemplate.isShippingFree==1}">
                <td>快递公司</td>
                <td>中国</td>
                <td>1</td>
                <td>0</td>
                <td>1</td>
                <td>0</td>
            </tr>
            </tbody>
        </table>
    </div>
</div>
</body>
<script src="http://cdn.viptool.cn/lib/jquery/2.2.4/jquery.min.js"></script>
<script src="../../resource/js/plugins/sweetalert/sweetalert.min.js" th:src="@{/resource/js/plugins/sweetalert/sweetalert.min.js}"></script>
<script src="../../resource/js/plugins/hot/Jquery.util.js" th:src="@{/resource/js/plugins/hot/Jquery.util.js?20181207055}"></script>
<link href="../../resource/lib/jBox/Skins/Green/jbox.css"  th:href="@{/resource/lib/jBox/Skins/Green/jbox.css}" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../resource/lib/jBox/jquery.jBox-2.3.min.js"  th:src="@{/resource/lib/jBox/jquery.jBox-2.3.min.js}"></script>

<script type="text/javascript" th:inline="javascript">
    var usedInfo = /*[[${freightTemplateUsedInfo}]]*/ [];
    /*<![CDATA[*/
    var templateListHandler = {
        setDefault: function (templateId) {
            hotUtil.ajaxCall("/freight/ajax/setDefault", {
                id: templateId
            }, function (ret) {
                if (ret.resultCode == 2000) {
                    hotUtil.alert("设置成功",function () {
                        window.location.reload();
                    })
                } else {
                    swal("操作失败！", ret.resultMsg, "error");
                }
            });
        },
        bindUsed: function () {
            $.each(usedInfo, function (o, item) {
                if (item[1] > 0) {
                    $("#template_" + item[0]).addClass("active");
                } else {
                    $("#template_" + item[1]).removeClass("active");
                }
            });
        },
        deleteTemplate: function (templateId) {
            swal({
                title: "确定要删除该模板?",
                text: "删除后将无法恢复，请谨慎操作！",
                type: "warning",
                showCancelButton: true,
                confirmButtonColor: "#DD6B55",
                confirmButtonText: "删除",
                closeOnConfirm: false
            }, function () {
                hotUtil.loading.show();
                hotUtil.ajaxCall("/freight/ajax/deleteTemplate", {
                    id: templateId
                }, function (ret) {
                    hotUtil.loading.close();
                    if (ret.resultCode === 2000) {
                        hotUtil.alert("删除成功",function () {
                            window.location.reload();
                        });
                    }
                    else {
                        swal("删除失败！", ret.resultMsg, "error");
                    }
                });
            });
        }
    };

    $(function () {
        templateListHandler.bindUsed();
    });
    /*]]>*/
</script>
</html>